home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / QuickDraw / Virtual Sphere 1.0.1 / Virtual Sphere Sample Code 1.1 / ObjectData.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-25  |  8.5 KB  |  302 lines  |  [TEXT/MPS ]

  1. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
  2. /* ObjectData.h
  3. /*
  4. /* Object definitions for Cube, House, and Icosahedron.
  5. /*
  6. /* Author: Michael Chen, Human Interface Group / ATG
  7. /* Copyright © 1991-1993 Apple Computer, Inc.  All rights reserved.
  8. /*
  9. /* Part of Virtual Sphere Sample Code Release v1.1
  10. /*•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••*/
  11.  
  12. /*=================================================================================================
  13. /* Cube
  14. /*-------------------------------------------------------------------------------------------------*/
  15. #define kCubeWidth        Long2Fix(200)
  16. #define kCubeDepth        Long2Fix(200)
  17. #define kCubeHeight        Long2Fix(200)
  18.  
  19. /* Vertex array */
  20. static Point3D gCubeVertices[] =
  21. {
  22.     { kCubeWidth/2,  kCubeDepth/2,  -kCubeHeight/2},
  23.     { kCubeWidth/2, -kCubeDepth/2,  -kCubeHeight/2},
  24.     {-kCubeWidth/2, -kCubeDepth/2,  -kCubeHeight/2},
  25.     {-kCubeWidth/2,  kCubeDepth/2,  -kCubeHeight/2},
  26.  
  27.     { kCubeWidth/2,  kCubeDepth/2,   kCubeHeight/2},
  28.     { kCubeWidth/2, -kCubeDepth/2,   kCubeHeight/2},
  29.     {-kCubeWidth/2, -kCubeDepth/2,   kCubeHeight/2},
  30.     {-kCubeWidth/2,  kCubeDepth/2,   kCubeHeight/2},
  31. };
  32.  
  33. /* Color array */
  34. static RGBColor gCubeColors[] = 
  35. {
  36.     { 3659,  3901, 65535},
  37.     { 4096,  4096,  4096},
  38.     {65535, 12157,  3994},
  39.     {65535, 35196,  5058},
  40.     {65535, 61127,  5185},
  41.     {38086, 44563, 55535},
  42. };
  43.  
  44. /* Indices array into vertex array */
  45. static Integer gCubeVertexIndices[] =
  46. {
  47.     4, 7, 6, 5,              /* front  face */
  48.     0, 1, 2, 3,              /* back   face */
  49.     5, 6, 2, 1,              /* bottom face */
  50.     4, 0, 3, 7,              /* top    face */
  51.     3, 2, 6, 7,              /* left   face */
  52.     1, 0, 4, 5,              /* right  face */
  53. };
  54.  
  55. /* Description of each polygon:
  56.  * Format: {# vertices, 1st index into Indices array, index into color array}
  57.  */
  58. static NetPolygon gCubePolys[] =
  59.     {4,  0, 0},              /* front  face */
  60.     {4,  4, 1},              /* back   face */
  61.     {4,  8, 2},              /* bottom face */
  62.     {4, 12, 3},              /* top    face */
  63.     {4, 16, 4},              /* left   face */
  64.     {4, 20, 5},              /* right  face */
  65. };
  66.  
  67. static PolygonNetData gCubeData =
  68. {
  69.     sizeof (gCubePolys)/sizeof(NetPolygon),    /* Polygon count */
  70.     gCubePolys,
  71.     sizeof (gCubeVertices)/sizeof(Point3D),    /* size of vertex array */
  72.     gCubeVertices,
  73.     gCubeVertexIndices,
  74.     gCubeColors,
  75. };
  76.  
  77.  
  78. /*=================================================================================================
  79. /* House
  80. /*-------------------------------------------------------------------------------------------------*/
  81. #define HOUSE_SCALE    5/4
  82. #define FLOOR        Long2Fix (-75)*HOUSE_SCALE    /* floor */
  83. #define WIDTH        Long2Fix (180)*HOUSE_SCALE    /* width  of house (floor plan) */
  84. #define DEPTH        Long2Fix (120)*HOUSE_SCALE    /* depth  of house (floor plan) */
  85. #define HEIGHT1        Long2Fix ( 45)*HOUSE_SCALE    /* height of house to bottom of roof */
  86. #define HEIGHT2        Long2Fix (105)*HOUSE_SCALE    /* height of house to top    of roof */
  87. #define DOOR_WIDTH    Long2Fix ( 30)*HOUSE_SCALE
  88. #define DOOR_HEIGHT    Long2Fix (-15)*HOUSE_SCALE
  89. #define DEPTH_ROOF    Long2Fix ( 30)*HOUSE_SCALE    /* depth  of top of roof */
  90.  
  91. /* Color array */
  92. static Point3D gHouseVertices[] =
  93. {
  94.     {-WIDTH/2,              FLOOR,     DEPTH/2},        /*  0 */
  95.     { WIDTH/2,              FLOOR,     DEPTH/2},
  96.     { WIDTH/2,            HEIGHT1,     DEPTH/2},
  97.     {-WIDTH/2,            HEIGHT1,     DEPTH/2},
  98.  
  99.     {-WIDTH/2,              FLOOR,    -DEPTH/2},        /*  4 */
  100.     {-WIDTH/2,            HEIGHT1,    -DEPTH/2},
  101.     { WIDTH/2,            HEIGHT1,    -DEPTH/2},
  102.     { WIDTH/2,              FLOOR,    -DEPTH/2},
  103.  
  104.     { WIDTH/2,            HEIGHT1,    -DEPTH/2},        /*  8 */
  105.     { WIDTH/2,            HEIGHT2,    -DEPTH_ROOF/2},
  106.     { WIDTH/2,            HEIGHT2,     DEPTH_ROOF/2},
  107.     { WIDTH/2,            HEIGHT1,     DEPTH/2},
  108.  
  109.     {-WIDTH/2,            HEIGHT1,     DEPTH/2},        /* 12 */
  110.     {-WIDTH/2,            HEIGHT2,     DEPTH_ROOF/2},
  111.     {-WIDTH/2,            HEIGHT2,    -DEPTH_ROOF/2},
  112.     {-WIDTH/2,            HEIGHT1,    -DEPTH/2},
  113.  
  114.     { WIDTH/2,            HEIGHT2,     DEPTH_ROOF/2},    /* 16 */
  115.     {-WIDTH/2,            HEIGHT2,     DEPTH_ROOF/2},
  116.     {-WIDTH/2,            HEIGHT2,    -DEPTH_ROOF/2},
  117.     { WIDTH/2,            HEIGHT2,    -DEPTH_ROOF/2},
  118.  
  119.     {-DOOR_WIDTH/2,          FLOOR,     DEPTH/2},        /* 20 */
  120.     { DOOR_WIDTH/2,          FLOOR,     DEPTH/2},
  121.     { DOOR_WIDTH/2,    DOOR_HEIGHT,     DEPTH/2},
  122.     {-DOOR_WIDTH/2,    DOOR_HEIGHT,     DEPTH/2},
  123. };
  124.  
  125. #define frontFaceColor        0
  126. #define backFaceColor        1
  127. #define rightFaceColor        2
  128. #define leftFaceColor        3
  129. #define bottomFaceColor        4
  130. #define frontRoofColor        5
  131. #define backRoofColor        6
  132. #define topRoofColor        7
  133. #define doorFaceColor        8
  134.  
  135. /* Color array */
  136. static RGBColor gHouseColors[] = 
  137. {
  138.     {0x0000,0xffff,0xffff},
  139.     {0x9700,0x9700,0x9700},
  140.     {0x1300,0x0600,0xc400},
  141.     {0x0000,0x5500,0x0000},
  142.     {0x6700,0x0000,0x0900},
  143.     {0xffff,0xffff,0x0000},
  144.     {0xad00,0x1e00,0x0001},
  145.     {0xffff,0x4800,0x0000},
  146.     {0x4000,0x4000,0x4000},
  147. };
  148.  
  149. /* Indices array into vertex array */
  150. static Integer gHouseVertexIndices[] =
  151. {
  152.      0,  1,  2,  3,            /* front face  */
  153.      4,  5,  6,  7,            /* back face   */
  154.      1,  7,  8,  9, 10, 11,    /* right face  */
  155.      0, 12, 13, 14, 15,  4,    /* left face   */
  156.      0,  4,  7,  1,         /* bottom face */
  157.     12, 11, 16, 17,            /* front roof  */
  158.     15, 18, 19,  8,            /* back roof   */
  159.     16, 19, 18, 17,            /* top of roof */
  160.     20, 21, 22, 23,            /* front door  */
  161. };
  162.      
  163. /* Description of each polygon:
  164.  * Format: {# vertices, 1st index into Indices array, index into color array}
  165.  */
  166. static NetPolygon gHousePolys[] =
  167.     {4,  0, frontFaceColor},
  168.     {4,  4, backFaceColor},
  169.     {6,  8, rightFaceColor},
  170.     {6, 14, leftFaceColor},
  171.     {4, 20, bottomFaceColor},
  172.     {4, 24, frontRoofColor},
  173.     {4, 28, backRoofColor},
  174.     {4, 32, topRoofColor},
  175.     {4, 36, doorFaceColor},
  176. };
  177.  
  178. static PolygonNetData gHouseData =
  179. {
  180.     sizeof (gHousePolys)/sizeof(NetPolygon),    /* polygonCount */
  181.     gHousePolys,
  182.     sizeof (gHouseVertices)/sizeof(Point3D),    /* sizeOfVertexArray */
  183.     gHouseVertices,
  184.     gHouseVertexIndices,
  185.     gHouseColors,
  186. };
  187.  
  188.  
  189. /*=================================================================================================
  190. /* Icosahedron
  191. /*-------------------------------------------------------------------------------------------------*/
  192. #define kCubeWidth        Long2Fix(200)
  193. #define kCubeDepth        Long2Fix(200)
  194. #define kCubeHeight        Long2Fix(200)
  195.  
  196. /* Vertex array */
  197. static Point3D gIcosahedronVertices[] =
  198. {
  199.     {        0,         0,  11010048},
  200.     {  9847675,         0,   4923866},
  201.     {  3043109,   9365692,   4923866},
  202.     { -7966924,   5788335,   4923866},
  203.     { -7966955,  -5788293,   4923866},
  204.     {  3043059,  -9365708,   4923866},
  205.     {  7966939,   5788314,  -4923866},
  206.     { -3043084,   9365700,  -4923866},
  207.     { -9847675,        26,  -4923866},
  208.     { -3043134,  -9365684,  -4923866},
  209.     {  7966909,  -5788356,  -4923866},
  210.     {        0,         0, -11010048},
  211. };
  212.  
  213. /* Color array */
  214. static RGBColor gIcosahedronColors[] = 
  215. {
  216.     {0x0000, 0x0000, 0xffff},    /* 0 blueColor    */
  217.     {0x0000, 0xffff, 0x0000},    /* 1 greenColor   */
  218.     {0x0000, 0xffff, 0xffff},    /* 2 yellowColor  */
  219.     {0xffff, 0x0000, 0x0000},    /* 3 redColor     */
  220.     {0xffff, 0x0000, 0xffff},    /* 4 magentaColor */
  221.     {0xffff, 0xffff, 0x0000},    /* 5 cyanColor    */
  222. };
  223.  
  224. /* Indices array into vertex array */
  225. static Integer gIcosahedronVertexIndices[] =
  226. {
  227.     0, 1, 2,
  228.     0, 2, 3,
  229.     0, 3, 4,
  230.     0, 4, 5,
  231.     0, 5, 1,
  232.     1, 6, 2,
  233.     2, 7, 3,
  234.     3, 8, 4,
  235.     4, 9, 5,
  236.     5, 10, 1,
  237.     1, 10, 6,
  238.     2, 6, 7,
  239.     3, 7, 8,
  240.     4, 8, 9,
  241.     5, 9, 10,
  242.     7, 6, 11,
  243.     8, 7, 11,
  244.     9, 8, 11,
  245.     10, 9, 11,
  246.     6, 10, 11,
  247. };
  248.  
  249. /* Description of each polygon:
  250.  * Format: {# vertices, 1st index into Indices array, index into color array}
  251.  */
  252. static NetPolygon gIcosahedronPolys[] =
  253.     {3,  0, 3},              /* face  0 */
  254.     {3,  3, 4},              /* face  1 */
  255.     {3,  6, 1},              /* face  2 */
  256.     {3,  9, 2},              /* face  3 */
  257.     {3, 12, 5},              /* face  4 */
  258.     {3, 15, 0},              /* face  5 */
  259.     {3, 18, 2},              /* face  6 */
  260.     {3, 21, 3},              /* face  7 */
  261.     {3, 24, 4},              /* face  8 */
  262.     {3, 27, 1},              /* face  9 */
  263.     {3, 30, 2},              /* face 10 */
  264.     {3, 33, 5},              /* face 11 */
  265.     {3, 36, 0},              /* face 12 */
  266.     {3, 39, 0},              /* face 13 */
  267.     {3, 42, 3},              /* face 14 */
  268.     {3, 45, 4},              /* face 15 */
  269.     {3, 48, 1},              /* face 16 */
  270.     {3, 51, 2},              /* face 17 */
  271.     {3, 54, 5},              /* face 18 */
  272.     {3, 57, 0},              /* face 19 */
  273. };
  274.  
  275. static PolygonNetData gIcosahedronData =
  276. {
  277.     sizeof (gIcosahedronPolys)/sizeof(NetPolygon),    /* Polygon count */
  278.     gIcosahedronPolys,
  279.     sizeof (gIcosahedronVertices)/sizeof(Point3D),    /* size of vertex array */
  280.     gIcosahedronVertices,
  281.     gIcosahedronVertexIndices,
  282.     gIcosahedronColors,
  283. };
  284.  
  285.  
  286. #ifdef xxx
  287.     {0.000000, 0.000000, 150.000000},
  288.     {134.163920, 0.000000, 67.082356},
  289.     {41.459067, 127.597426, 67.082356},
  290.     {-108.540724, 78.859804, 67.082356},
  291.     {-108.541142, -78.859228, 67.082356},
  292.     {41.458390, -127.597646, 67.082356},
  293.     {108.540933, 78.859516, -67.082356},
  294.     {-41.458728, 127.597536, -67.082356},
  295.     {-134.163920, 0.000356, -67.082356},
  296.     {-41.459405, -127.597316, -67.082356},
  297.     {108.540515, -78.860092, -67.082356},
  298.     {0.000000, 0.000000, -150.000000},
  299. #endif